////////////////////////////////////////////////////////////////////////////////
//
//	This file is part of Woozox, see <http://code.google.com/p/woozox/>.
//
//	Copyright 2008-2009 Florian David
//
//	Woozoo is free software: you can redistribute it and/or modify
//	it under the terms of the GNU Lesser General Public License as 
//	published by the Free Software Foundation, either version 3 of 
//	the License, or (at your option) any later version.
//
//	Woozoo is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//	GNU General Public License for more details.
//
//	You should have received a copy of the GNU Lesser General Public 
//	License along with Woozoo. If not, see <http://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////
package org.woozoo.xhtml.core.base.selector
{
	import org.woozoo.xhtml.core.base.Element;
	
	/**
	 * @private
	 * */
	internal final class SelectorOperatorNot extends AbstractSelectorOperator
	{
		override protected function _operateElements() : Array {
			var selectorStr : String = str.slice(5, str.length - 1);
			
			var selectorParser : SelectorParser = new SelectorParser();
			selectorParser.init(selectorStr);
			selectorParser.next();
			
			var operator : ISelectorOperator = SelectorOperatorFactory.factory(selectorParser.matchIndex);
			operator.init(selectorParser.analyse, elements, document, 1);
			var res : Array = operator.operate();
			var len : int = res.length;
			for (var i : int = elements.length - 1; i >= 0; i--) {
				var element : Element = elements[i];
				if (res.indexOf(element) >= 0) {
					elements.splice(i, 1);
				}				
			}
			return elements;			
		}
	}
}